package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    Employee getByUsername(String username);

    /**
     * 员工分页查询
     * @param name
     * @return
     */
    List<Employee> pageList(String name);

    /**
     * 新增员工
     * @param employee
     */
    @AutoFill(OperationType.INSERT)
    void add(Employee employee);

    /**
     * 根据id查询员工
     * @param employeeDTO
     * @return
     */
    Employee findByCondition(EmployeeDTO employeeDTO);

    /**
     * 启用、禁用员工账号
     * @param employee
     */
    @Update("update employee set status=#{status} where id=#{id}")
    void updateStatus(Employee employee);

    /**
     * 编辑员工信息
     * @param employeeDTO
     */
    @AutoFill(OperationType.UPDATE)
    @Update("update employee set id_number=#{idNumber},name=#{name},phone=#{phone},sex=#{sex},username=#{username} " +
            "where id=#{id}")
    void updateInfo(EmployeeDTO employeeDTO);

    /**
     * 修改密码
     * @param passwordEditDTO
     */
    @Update("update employee set password=#{newPassword} where id=#{empId}")
    void updatePassword(PasswordEditDTO passwordEditDTO);
}
